package com.zhangsun.springActiveMq.consumer;

import com.zhangsun.springActiveMq.common.ActiveMqConstant;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.concurrent.TimeUnit;

@Component
public class TopicConsumer {

    @JmsListener(destination = ActiveMqConstant.TOPIC_HELLO_1, containerFactory = ActiveMqConstant.TOPIC_LISTENER)
    public void consumer1(String msg) {
        System.out.println("topic1：" + msg);
    }

    @JmsListener(destination = ActiveMqConstant.TOPIC_HELLO_1, containerFactory = ActiveMqConstant.TOPIC_LISTENER)
    public void consumer2(String msg) {
        System.out.println(new Date());
        try {
            TimeUnit.SECONDS.sleep(5L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(new Date());
        System.out.println("topic2：" + msg);
    }

}
